package com.itheima.dao;

import com.github.pagehelper.Page;
import com.itheima.pojo.Permission;
import com.itheima.pojo.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface RoleDao {
/*

    @Select("SELECT * FROM t_role WHERE id IN(SELECT role_id FROM t_user_role WHERE user_id=#{user_id})")
    @Results({
            @Result(id = true,property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "keyword", column = "keyword"),
            @Result(property = "description", column = "description"),
            @Result(property = "permissions",column = "id",
                    javaType = Set.class,
                    many = @Many(select = "com.itheima.dao.PermissionDao.findPermission"))
    })
      public Set<Role>  findRole(Integer user_id);
*/

    public Set<Role> findByUserId(Integer userId);

    public List<Role> findallrole();


    void setRoleAndPermission(Map<String, Integer> map);

    void setRoleAndMenu(Map<String, Integer> map);

    void add(Role role);

    Page<Role> selectByCondition(String queryString);

    @Select("select * from t_role where id=#{id}")
    Role findById(Integer id);

    @Select(" SELECT permission_id FROM t_role_permission WHERE role_id=#{id}")
    List<Integer> findPermissionIdsByRoleId(Integer id);

    @Select(" SELECT menu_id FROM t_role_menu WHERE role_id=#{id}")
    List<Integer> findMenuIdsByRoleId(Integer id);

    void edit(Role role);

    void deleteRoleAndPermissionAssociation(Integer id);

    void deleteRoleAndMenuAssociation(Integer id);

    @Delete("delete from t_role where id = #{id}")
    void del(Integer id);

    Integer findRoleIdByUserId(Integer userId);
}
